<!--#
layout("/layouts/store.html"){
#-->
<style>
    .rule-group-cnd,.rule-group-act{
        margin: 5px 5px 5px 15px; padding: 5px;display: none;
    }
    .rule-cnd-def ul{
        list-style-type:none
    }
    .rule-cnd-def ul li{
        padding: 5px;
    }
    .cnd-panel{
        overflow-x:auto; white-space:nowrap;
    }
    .cnd-del{
        cursor:pointer;padding: 5px;
    }

    .rule-price-input-sm{
        width: 60px;
    }
    .rule-input-sm{
        width: 50px;
    }
    .member-lvs{
        display: inline-block
    }
    .member-lv-inline {
        position: relative;
        display: inline-block;
        padding-top: 7px;
        padding-left: 1px;
        margin-bottom: 0;
        font-weight: 400;
        vertical-align: middle;
    }
    .rule-input-rate{
        width: 100px;min-width: 80px;
    }
    .rule-input-price{
        width: 120px;min-width: 100px;
    }
    .rule-input-number{
        width: 60px;min-width: 40px;
    }
</style>
<script src="${base!}/assets/platform/vendor/ueditor/ueditor.config.js"></script>
<script src="${base!}/assets/platform/vendor/ueditor/ueditor.all.js"></script>
<link rel="stylesheet" href="${base!}/assets/platform/vendor/layui/css/layui.css">
<header class="header navbar bg-white shadow">
    <div class="btn-group tool-button">
        <a class="btn btn-primary navbar-btn" href="${base}/store/sales/coupon" id="goBack" data-pjax><i class="ti-angle-left"></i>${msg['globals.button.back']}</a>
    </div>
    <div class="pull-right">
        <div class="btn-group tool-button">
            <!--<button class="btn btn-primary navbar-btn js-to-check" data-loading-text="${msg['globals.button.submit.tip']}" >保存并提交审核</button>-->
            <button class="btn btn-primary navbar-btn js-save" data-loading-text="${msg['globals.button.submit.tip']}" > ${msg['globals.button.save']}</button>
            <a id="doLink" href="${base}/store/sales/coupon/add" data-pjax></a>
        </div>
    </div>
</header>

<div class="content-wrap">
    <div class="wrapper" style="min-height:500px;">
        <section class="panel panel-form">
            <form id="addForm" role="form" class="form-horizontal parsley-form" data-parsley-validate action="${base}/store/sales/coupon/addDo" method="post">
                <input type="hidden" name="checkStatus" value="2"/>
                <!--<div class="box-tab ">-->
                    <!--<ul class="nav nav-tabs">-->
                        <!--<li class="active"><a href="#base" data-toggle="tab">优惠券</a></li>-->
                        <!--<li class="" id="rule_order_tab" ><a href="#rule_order" data-toggle="tab">规则</a></li>-->
                    <!--</ul>-->
                    <div class="tab-content">
                        <!--优惠券-->
                        <div class="tab-pane fade active in" id="base">
                            <div class="row mb10 mt10">
                                <div class="col-lg-12">
                                    <div class="form-group">
                                        <label for="name" class="col-sm-2 control-label">${msg['sales.coupon.column.name']}</label>
                                        <div class="col-sm-5">
                                            <input type="text" id="name" class="form-control" name="name" data-parsley-required="true" placeholder="${msg['sales.coupon.column.name']}">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="codeprefix" class="col-sm-2 control-label">${msg['sales.coupon.column.codeprefix']}</label>
                                        <div class="col-sm-2">
                                            <input type="text" id="codeprefix" class="form-control" name="codeprefix" data-parsley-required="true" placeholder="${msg['sales.coupon.column.codeprefix']}">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label for="value" class="col-sm-2 control-label">面值</label>
                                        <div class="col-sm-2">
                                            <input type="text" id="value" class="form-control" name="value" data-parsley-required="true" placeholder="面值">
                                        </div>
                                    </div>
<!--                                    <div class="form-group">-->
<!--                                        <label class="col-sm-2 control-label">${msg['sales.coupon.column.type']}</label>-->
<!--                                        <div class="col-sm-8 radio">-->
<!--                                            <div class="form-inline">-->
<!--                                                <label><input type="radio" class="radioType" name="type" value="1" checked>订单满减优惠劵</label><span>（此类优惠券，顾客当订单金额达到配置金额是便可用优惠劵抵扣。）</span>-->
<!--                                            </div>-->
<!--                                            <div class="form-inline">-->
<!--                                                <label><input type="radio" class="radioType" name="type" value="2" >订单免运费优惠券</label><span>（当购买商品数量达到配置的数量时，则进行免运费。）</span>-->
<!--                                            </div>-->
<!--                                            <div class="form-inline">-->
<!--                                                <label><input type="radio" class="radioType" name="type" value="3" >订单打折优惠券</label><span>（当购买商品数量达到配置时，可使用此劵的折扣额）</span>-->
<!--                                            </div>-->
<!--                                        </div>-->
<!--                                    </div>-->
                                    <!--获取方式-->
                                    <!--<div class="form-group">-->
                                    <!--<label class="col-sm-2 control-label">${msg['sales.coupon.column.send_type']}</label>-->
                                    <!--<div class="col-sm-8 form-inline radio">-->
                                    <!--<label><input type="radio" class="" name="send_type" value="receive" checked>领取(店铺领取或通过code领取)</label>-->
                                    <!--<label><input type="radio" class="" name="send_type" value="score">积分兑换</label>-->
                                    <!--<input type="text" id="score" class="form-control input-sm" style="display: none" name="score" value="" data-parsley-required="true" placeholder="${msg['sales.coupon.column.score']}">-->
                                    <!--</div>-->
                                    <!--</div>-->
                                    <div class="form-group">
                                        <label class="col-sm-2 control-label">${msg['sales.coupon.column.enabled']}</label>
                                        <div class="col-sm-1 switcha">
                                            <div class="mr15">
                                                <input type="hidden" name="disabled" value="0"/>
                                                <input type="checkbox" name="enabled" class="js-switch-blue" checked >
                                            </div>
                                        </div>
                                    </div>

<!--                                    <div class="form-group">-->
<!--                                        <label class="col-sm-2 control-label">有效期</label>-->
<!--                                        <div class="col-sm-8 form-inline">-->
<!--                                            <div class="layui-form">-->
<!--                                                <div class="layui-form-item">-->
<!--                                                    <div class="layui-inline">-->
<!--                                                        <div class="layui-input-inline">-->
<!--                                                            <input type="text" name="tmp_sartAt" class="layui-input" id="test29" placeholder="选择日期">-->
<!--                                                        </div>-->
<!--                                                    </div>-->
<!--                                                </div>-->
<!--                                                <span>至</span>-->
<!--                                                <div class="layui-form-item">-->
<!--                                                    <div class="layui-inline">-->
<!--                                                        <div class="layui-input-inline">-->
<!--                                                            <input type="text" name="tmp_endAt" class="layui-input" id="test30" placeholder="选择日期">-->
<!--                                                        </div>-->
<!--                                                    </div>-->
<!--                                                </div>-->
<!--                                            </div>-->
<!--                                        </div>-->
<!--                                    </div>-->

<!--                                    <div class="form-group">-->
<!--                                        <label class="col-sm-2 control-label">推荐人获得券-是否使用当前券</label>-->
<!--                                        <div class="col-sm-1 switcha">-->
<!--                                            <div class="mr15">-->
<!--                                                <input type="hidden" name="isThisData" value="0"/>-->
<!--                                                <input type="checkbox" name="isThis" class="js-switch-blue" checked >-->
<!--                                            </div>-->
<!--                                        </div>-->
<!--                                    </div>-->

<!--                                    <div class="form-group has-feedback" id="tjCoupon" style="display: none;">-->
<!--                                        <label for="tjCouponId" class="col-sm-2 control-label">推荐人获取的优惠券</label>-->

<!--                                        <div class="col-sm-4">-->
<!--                                            <div class="input-group">-->
<!--                                                <input id="tjCouponId" type="text" class="form-control" placeholder="推荐人获取的优惠券" disabled-->
<!--                                                       value=""/>-->

<!--                                       <span class="input-group-btn">-->
<!--                                            <button type="button" class="btn btn-primary" onclick="selectCoupon()"-->
<!--                                                    data-toggle="modal" data-target="#dialogSelectParentUnit">-->
<!--                                                <i class="ti-plus"></i>推荐人获取的优惠券-->
<!--                                            </button>-->
<!--									    </span>-->
<!--                                            </div>-->
<!--                                            <input type="hidden" id="tjCouponIdValue" name="tjCouponId" value="">-->
<!--                                        </div>-->
<!--                                    </div>-->

<!--                                    <div class="form-group">-->
<!--                                        <label for="imageUrl" class="col-sm-2 control-label">上传列表封面图片</label>-->
<!--                                        <div class="col-sm-6">-->
<!--                                            <div id="imgQueue"></div>-->
<!--                                            <div>-->
<!--                                                <input id="file_upload_img" name="file_upload" type="file"-->
<!--                                                       multiple="false">-->
<!--                                            </div>-->
<!--                                            <div id="img" style="padding: 5px;"></div>-->
<!--                                            <input type="hidden" id="imageUrl" name="imageUrl" value="">-->
<!--                                        </div>-->
<!--                                        <div class="col-sm-2" style="color: red;">建议尺寸：145*100</div>-->
<!--                                    </div>-->

                                </div>
                            </div>
                        </div>
                    </div>
                <!--</div>-->
            </form>
        </section>
    </div>
</div>
<script src="${base!}/assets/platform/vendor/layui/layui.all.js"></script>
<script type="application/javascript">

    $(document).ready(function () {

        var form = layui.form;
        layui.use(['form', 'layedit', 'laydate'], function(){
            var laydate = layui.laydate;

            form.render();
            //直接嵌套显示
            laydate.render({
                elem: '#test29'
                ,theme: 'molv'
                ,type: 'datetime'
                ,value: new Date()
                ,done: function(value, date, endDate){
                    console.log(value); //得到日期生成的值，如：2017-08-18
                    console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
                    console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。
                }
            });
            laydate.render({
                elem: '#test30'
                ,theme: 'molv'
                ,value: new Date()
                ,type: 'datetime'
                ,done: function(value, date, endDate){
                    console.log(value); //得到日期生成的值，如：2017-08-18
                    console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
                    console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。
                }
            });
        });

        //保存
        $(".js-save").click(function () {
            $('#addForm').submit();

        });

        $('#addForm').ajaxForm({
            dataType: 'json',
            beforeSubmit: function (arr, form, options) {
                form.find("button:submit").button("loading");
            },
            success: function (data, statusText, xhr, form) {
                if (data.code == 0) {
                    Toast.success(data.msg);
                    window.location.href="${base}/store/sales/coupon";
                } else {
                    Toast.error(data.msg);
                }
                form.find("button:submit").button("reset");
            }
        });



        //form表单基础效果
        myForm.init();

        $('.js-start-time').datetimepicker({
            language:  "${lang!'zh-CN'}",
            format:'yyyy-mm-dd hh:ii:ss',
            pickerPosition: 'bottom-left',
            weekStart: 1,
            todayBtn:  1,
            autoclose: 1,
            todayHighlight: 1,
            startView: 2,
            forceParse: 0,
            showMeridian: 1,
            endDate: new Date("${@date.getDate()}")
        }).on("changeDate", function (e) {
            $('.js-end-time').datetimepicker('setStartDate', e.date);
        });

        $('.js-end-time').datetimepicker({
            language:  "${lang!'zh-CN'}",
            format:'yyyy-mm-dd hh:ii:ss',
            pickerPosition: 'bottom-left',
            weekStart: 1,
            todayBtn:  1,
            autoclose: 1,
            todayHighlight: 1,
            startView: 2,
            forceParse: 0,
            showMeridian: 1,
            startDate: new Date("${@date.getDate()}")
        }).on("changeDate", function (e) {
            $('.js-start-time').datetimepicker('setEndDate', e.date);
        });

        //上传图片
        $('#file_upload_img').uploadifive({
            'auto': true,
            'multi': false,
            'width': '100%',
            'height': '35',
            'buttonText': '选择图片',
            'fileType': 'image/jpg,image/jpeg,image/png',
            'fileSizeLimit': 2048,
            'queueSizeLimit': 1,
            'overrideEvents': ['onDialogClose', 'onError'],
            'formData': {},
            'queueID': 'imgQueue',
            'uploadScript': '${base}/open/file/upload/image',
            'onUploadComplete': function (file, data) {
                data = JSON.parse(data);
                if (data.code == 0) {
                    Toast.success(data.msg);
                    $("#img").html("<img src='" + data.data + "' style='width:150px;height:95px;'>");
                    $("#imageUrl").val(data.data);
                } else {
                    clearFile();
                    Toast.error(data.msg);
                }
            },
            'onDrop': function (file, fileDropCount) {
                clearFile();
            },
            'onClearQueue': function (queue) {
                clearFile();
            },
            'onError': function (errorType, file) {
                if (file != 0) {
                    // var settings = $("#" + fileuploadId).uploadifive().settings;
                    switch (errorType) {
                        case 'UPLOAD_LIMIT_EXCEEDED':
                            Toast.error("上传的文件数量已经超出系统限制的1个文件！");
                            break;
                        case 'FILE_SIZE_LIMIT_EXCEEDED':
                            Toast.error("文件大小超出系统限制的2M大小！");
                            break;
                        case 'FORBIDDEN_FILE_TYPE':
                            Toast.error("文件类型不正确！");
                            break;
                    }
                }
            },
            'onCancel': function () {
                clearFile();
            }
        });



    })



    /**
     * 上传图片
     */
    function clearFile() {
        $("#img").html("");
        $("#imgQueue").html("");
        $("#imageUrl").val("");
    }

    //禁用启用颠倒了
    $("[name='enabled']").change(function () {
        if (this.checked) {
            $("[name='disabled']:hidden").val(0);
        } else {
            $("[name='disabled']:hidden").val(1);
        }
    });

    //禁用启用颠倒了
    $("[name='isThis']").change(function () {
        if (this.checked) {
            $("[name='isThisData']:hidden").val(0);
            $("#tjCoupon").css("display","none")
        } else {
            $("[name='isThisData']:hidden").val(1);
            $("#tjCoupon").css("display","block")
        }
    });

    var indexId ="";
    function selectCoupon() {
        indexId = layer.open({
            type: 2,
            title: '很多时候，我们想最大化看，比如像这个页面。',
            shadeClose: true,
            shade: false,
            maxmin: true, //开启最大化最小化按钮
            area: ['893px', '600px'],
            content: '${base!}/store/sales/coupon/indexSelect'
        });
    }





</script>


<!--#}#-->


